<template>
  <div class="playlist">
    <!-- 头部区域 -->
    <div class="playlist-top">
      <!-- 左侧播放全部 -->
      <div class="left">
        <svg class="icon " aria-hidden="true">
          <use xlink:href="#icon-bofang1"></use>
        </svg>
        <div class="text">
          <div class="title">播放全部</div>
          <div class="num">(共{{formatNumber(playlist.tracks.length)}}首)</div>
        </div>
      </div>
      <!-- 右侧收藏 -->
      <div class="btn">
         + 收藏({{formatNumber(playlist.subscribedCount)}})
      </div>
    </div>
    <!-- 歌单列表 -->
    <div class="list">
      <div class="playItem" v-for="(item, index) in playlist.tracks" :key="item.id">
        <div class="left">
          <!-- 左侧索引 -->
          <div class="index">{{ index + 1 }}</div>
          <!-- 歌曲 -->
          <div class="content" @click="play(index)">
            <div class="title">{{ item.al.name }}</div>
            <div class="author">
              <span class="tag" v-for="(tag,i) in playlist.tags" :key="i">
                {{tag}}
              </span>
              <span class="name">{{ item.ar[0].name }}</span>
            </div>
          </div>
        </div>
        <div class="right">
          <svg class="icon " aria-hidden="true" v-if="item.mv">
            <use xlink:href="#icon-bofang"></use>
          </svg>
          <svg class="icon " aria-hidden="true">
            <use xlink:href="#icon-gengduo1"></use>
          </svg>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import playMusic from '@/components/playMusic.vue'
import { formatNumber } from '@/util/formatNumber.js'
import { onMounted, ref } from 'vue';
import { useStore } from 'vuex'

const props = defineProps({
  playlist: {
    type: Object,
    default: {}
  }
})

// const show = ref(false);

const store = useStore()

// 点击播放歌曲
const play = (index) => {
  store.commit('playCurrentIndex', index)
}



</script>

<style lang="less" scoped>
.playlist {
  width: 7.5rem;
  margin-top: 0.4rem;
  padding: 0.1rem 0.1rem 0 0.3rem;
  background-color: #fff;
  border-top-left-radius: 0.3rem;
  border-top-right-radius: 0.3rem;
  margin-bottom: 1.2rem;
  .playlist-top {
    display: flex;
    justify-content: space-between;
    height: 1rem;
    align-items: center;
    .left {
      display: flex;
      align-items: center;
      .text {
        display: flex;
        align-items: center;
      }
      .icon {
        width: 0.4rem;
        height: 0.4rem;
      }
      .title {
        padding-left:0.2rem;
        font-size: 0.3rem;
        font-weight: 700;
      }
      .num {
        font-size: 0.2rem;
        color: #ccc;
      }
    }
    .btn {
      font-size: 0.2rem;
      color: #fff;
      background-color: orangered;
      height: 0.6rem;
      line-height: 0.6rem;
      padding: 0 0.2rem;
      border-radius: 0.6rem;
    }
  }
  .list {
    .playItem {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 1.2rem;
      .left {
        display: flex;
        align-items: center;
        color: #666;
        .index {
          width: 0.2rem;
          text-align: center;
        }
        .content {
          margin-left: 0.4rem;
        }
        .title {
          font-size: 0.28rem;
          // font-weight: 700;
          color: #000;
          margin-bottom: 0.06rem;
        }
        .tag {
          margin-right: 0.1rem;
          font-size: 0.2rem;
          color: #ff4500;
          border: 0.1px solid #ff4500;
          border-radius: 0.1rem;
          padding:0 0.03rem;
        }
        .name {
          color: #666;
          font-size: 0.26rem;
        }
      }
      .right {
        .icon {
          margin: 0 0.2rem;
        }
      }
    }
  }
}

</style>